home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / KEYBOARD.SWG / 0005_INT09 Keyboard handler #3.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  4KB  |  92 lines

  1. {
  2. >  Does anybody know of a way to reWrite the keyboard routines, to be abl
  3. >  to read several keys at once? ReadKey will only read the last keypress
  4. >  anything else I've tried can only read the last key you have pressed d
  5. >
  6. >  For example, in many games it will let you move Forward (With the Forw
  7. >  arrow key) and shoot at the same time, With the space bar...Any sugges
  8. Oops, I Forgot to include one of the Units you'll need to do this. I've already
  9. sent you POLL.PAS and TWOKEYS.PAS.  Here's KEYinTR.PAS:
  10. }
  11. Unit KeyIntr ;  { support For inT 09 routines } { Turbo Pascal 5.5 } Interface
  12. Procedure CLI ;  Inline( $FA ) ;   { disable interrupts } Procedure STI ;
  13. Inline( $FB ) ;   { enable interrupts } { cannot be used outside an interrupt
  14. Procedure } Procedure JumpInterrupt( p : Pointer ) ; { see TP5 Ref p 222
  15. } Inline( $5B/$58/                         { POP  BX, AX   AX:BX = p }
  16.         $89/$EC/                         { MOV  SP, BP             }
  17.         $87/$46/$10/                     { XCHG AX, [BP+10H]       }
  18.         $87/$5E/$0E/                     { XCHG BX, [BP+0EH]       }
  19.         $5D/$07/$1F/$5F/$5E/             { POP  BP, ES, DS, DI, SI }
  20.         $5A/$59/                         { POP  DX, CX             }
  21.         $FA/                             { CLI                     }
  22.         $CB ) ;                          { RETF          jmp Far p }
  23.  
  24. Function Control_Pressed : Boolean ;
  25. Procedure EOI ;                         { end of interrupt to 8259 } Function
  26. ReadScanCode : Byte ;             { read keyboard } Procedure ResetKeyboard ;
  27.                { prepare For next key } Procedure StoreKey( Scan, Key : Byte )
  28. ;
  29.                                    { put key in buffer For inT 16 }
  30. Implementation Uses Crt ;  { Sound, NoSound } Type
  31.    Address = Record                  { used in Pointer manipulation }
  32.                 offset : Word ;
  33.                 Segment : Word ;
  34.              end ;
  35. Const
  36.    BiosDataSegment = $40 ;
  37. Var
  38.    KeyState       : Word Absolute BiosDataSegment:$0017 ;
  39.    KeyBufferHead  : Word Absolute BiosDataSegment:$001A ;
  40.    KeyBufferTail  : Word Absolute BiosDataSegment:$001C ;
  41.    KeyBufferStart : Word Absolute BiosDataSegment:$0080 ;
  42.    KeyBufferend   : Word Absolute BiosDataSegment:$0082 ;
  43.  
  44.  
  45. Function Control_Pressed : Boolean ;
  46. begin
  47. Control_Pressed := ( KeyState and  4 ) = 4 ; end ;
  48.  
  49. Procedure EOI ;  { end of interrupt to 8259 interrupt controller } begin
  50.    CLI ;
  51.    Port[$20] := $20 ;     { see TP5 ref p 211 } end ;
  52.  
  53. Function ReadScanCode : Byte ;
  54. begin
  55. ReadScanCode := Port[$60] ;
  56. end ;
  57.  
  58. Procedure ResetKeyboard ;      { prepare For next key } Var
  59.    N : Byte ;
  60. begin
  61.    N := Port[$61] ;
  62.    Port[$61] := ( N or $80 ) ;
  63.    Port[$61] := N ;
  64. end ;
  65.  
  66. Procedure StoreKey( Scan, Key : Byte ) ; Var                { put key in buffer
  67. that inT 16 reads }
  68.    P : ^Word ;
  69.    N : Word ;
  70. begin
  71.    address(P).segment := BiosDataSegment ;
  72.    N := KeyBufferTail ;
  73.    address(P).offset := N ;
  74.    Inc( N, 2 ) ;                      { advance Pointer two Bytes }
  75.    if( N = KeyBufferend ) then        { end of the circular buffer }
  76.       N := KeyBufferStart ;
  77.    if( N = KeyBufferHead ) then       { buffer full }
  78.    begin
  79.       EOI ;               { EOI must be done beFore Exit            }
  80.       Sound( 2200 ) ;     {    but beFore anything that takes a lot }
  81.       Delay( 80 ) ;       {     of time and can be interrupted      }
  82.       NoSound ;
  83.    end
  84.    else
  85.    begin          { high Byte is scan code, low is ASCII }
  86.       P^ := Scan * $100 + Key ;       { store key in circular buffer }
  87.       KeyBufferTail := N ;            { advance tail Pointer }
  88.       EOI ;
  89.    end ;
  90. end ;
  91. end.
  92.